package mcpclient

import (
	"context"
	"log"

	"github.com/cloudwego/eino-ext/components/tool/mcp"
	"github.com/cloudwego/eino/schema/tool"
)

// GetMCPClient 获取MCP客户端
func GetMCPClient(ctx context.Context, config *mcp.Config) *client.SSEMCPClient {
	cli, err := client.NewSSEMCPClient(config.Cli)
	if err != nil {
		log.Fatal(err)
	}
	return cli
}

// ConvertToEinoTools 将MCP客户端转换为Eino工具
func ConvertToEinoTools(ctx context.Context, cli *client.SSEMCPClient) []tool.BaseTool {
	tools, err := mcp.GetTools(ctx, &mcp.Config{Cli: cli})
	if err != nil {
		log.Fatal(err)
	}
	return tools
}

// GetEinoTools 获取Eino工具
func GetEinoTools(ctx context.Context, config *mcp.Config) []tool.BaseTool {
	cli := GetMCPClient(ctx, config)
	return ConvertToEinoTools(ctx, cli)
}
